package com.mmall.concurrency.threads.join;

public class DemoTest{
    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() { //线程 1
            @Override
            public void run() {
                try {
                    Thread.sleep (5000 ); //线程 1 休眠 5 秒钟
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println ("线程 1 休眠 5 秒钟，执行完毕。");
            }
        });

        Thread threadTwo = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep (10000 ); //线程 2 修眠 10 秒钟
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println ("线程 2 修眠 10 秒钟，执行完毕。");
            } //线程 2


    });

    Thread threadThree = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep (8000 ); //线程 3 修眠 8 秒钟
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println ("线程 3 修眠 8 秒钟，执行完毕。");
        }//线程 3



});

        Long startTime = System.currentTimeMillis();
        threadOne. start();threadTwo. start();threadThree. start();
        System.out.println("等待三个线程全部执行完毕再继续向下执行,我要使用 join 方法了。");
        threadOne.join(); //线程 1 调用 join 方法
        threadTwo.join(); //线程 2 调用 join 方法
        threadThree.join(); //线程 3 调用 join 方法
        Long endTime = System.currentTimeMillis();
        System.out.println("三个线程都执行完毕了，共用时： "+ (endTime - startTime) + "毫秒");
        }
        }
